package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Wholesaler;
import com.ruoyi.system.service.IWholesalerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 批发商管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-27
 */
@RestController
@RequestMapping("/system/wholesaler")
public class WholesalerController extends BaseController
{
    @Autowired
    private IWholesalerService wholesalerService;

    /**
     * 查询批发商管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:wholesaler:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wholesaler wholesaler)
    {
        startPage();
        List<Wholesaler> list = wholesalerService.selectWholesalerList(wholesaler);
        return getDataTable(list);
    }

    /**
     * 导出批发商管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:wholesaler:export')")
    @Log(title = "批发商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Wholesaler wholesaler)
    {
        List<Wholesaler> list = wholesalerService.selectWholesalerList(wholesaler);
        ExcelUtil<Wholesaler> util = new ExcelUtil<Wholesaler>(Wholesaler.class);
        util.exportExcel(response, list, "批发商管理数据");
    }

    /**
     * 获取批发商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wholesaler:query')")
    @GetMapping(value = "/{wholesalerId}")
    public AjaxResult getInfo(@PathVariable("wholesalerId") Long wholesalerId)
    {
        return success(wholesalerService.selectWholesalerByWholesalerId(wholesalerId));
    }

    /**
     * 新增批发商管理
     */
    @PreAuthorize("@ss.hasPermi('system:wholesaler:add')")
    @Log(title = "批发商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wholesaler wholesaler)
    {
        return toAjax(wholesalerService.insertWholesaler(wholesaler));
    }

    /**
     * 修改批发商管理
     */
    @PreAuthorize("@ss.hasPermi('system:wholesaler:edit')")
    @Log(title = "批发商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wholesaler wholesaler)
    {
        return toAjax(wholesalerService.updateWholesaler(wholesaler));
    }

    /**
     * 删除批发商管理
     */
    @PreAuthorize("@ss.hasPermi('system:wholesaler:remove')")
    @Log(title = "批发商管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wholesalerIds}")
    public AjaxResult remove(@PathVariable Long[] wholesalerIds)
    {
        return toAjax(wholesalerService.deleteWholesalerByWholesalerIds(wholesalerIds));
    }
}
